package com.site.util.base.converter;

import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

import com.site.util.StringUtils;


public class FloatTypeConverter extends StrutsTypeConverter {

	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {
		if (StringUtils.isEmpty(values[0])) {
			return null;
		}

		Float result;
		try {
			result = Float.parseFloat(values[0]);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new IllegalArgumentException(e);
		}
		return result;
	}

	@Override
	public String convertToString(Map context, Object object) {
		if (object != null ) {
			return String.valueOf(object);
		}
		return null;
	}

}
